<?php
/**
 * Created by PhpStorm.
 * User: chenqinglin
 * Date: 17-8-2
 * Time: 下午5:34
 */

namespace App\Services\Impl;


use App\Models\OrderEvaluate;
use App\Models\Order;
use App\Models\OrderStatus;
use App\Services\IEvaluateService;
use App\Common\Constant\Params;
use App\Events\OrderEvaluated;

/** 超时未评价的订单会自动评价实现
 * Class EvaluateServiceImpl
 * @package App\Services\Impl
 */
class EvaluateServiceImpl implements IEvaluateService
{

    /**自动完成师傅评价
     * @param $order_id
     * @return mixed
     */
    public function evaluateMaster($order_id)
    {
        $order = Order::find($order_id);
        $content= '15天未评价系统默认好评！';

        $time = time();
        $evaluate = OrderEvaluate::firstOrCreate([
            'oe_orderid'=>$order->id,
            'oe_score' => Params::EVALUATE_POSITIVE,
            'oe_quality' => Params::EVALUATE_QUALITY_FIRE,
            'oe_attitude' => Params::EVALUATE_ATTITUDE_FIRE,
            'oe_ontime' => Params::EVALUATE_TIME_FIRE,
            'oe_meid'=>$order->merchant_id,
            'oe_content' => $content,
        ]);

        $data = [
            'evaluate_status'=>Params::ORDER_EVALUATE_ALREADY,
        ];
        $ret = OrderStatus::where('order_id',$order_id)->update($data);

        //echo ' 评价id '.$evaluate->oe_id.' order_id '.$order->id.' '.$order->merchant_id;
        event(new OrderEvaluated($evaluate->oe_id));

        return $ret;
    }
}